package com.mall.product.server.controller;

import com.mall.common.core.domain.Result;
import com.mall.common.security.annotation.RequiresPermissions;
import com.mall.product.common.domain.PmsShop;
import com.mall.product.common.domain.PmsSkuInfo;
import com.mall.product.common.domain.PmsSpuInfo;
import com.mall.product.server.service.IPmsSkuInfoService;
import com.mall.product.server.service.impl.PmsSkuInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import java.util.List;

@RestController
@RequestMapping("skuInfo")
public class PmsSkuInfoController {

    @Autowired
    private IPmsSkuInfoService pmsSkuInfoService;


    /**
     * 库存预热
     */
    @PostConstruct
    public void init(){
        System.out.println("开始进行库存预热");
        pmsSkuInfoService.init();
    }


    /**
     * 获取sku信息详细信息
     */
    @GetMapping("/findSkuInfoBySkuId/{skuId}")
    public Result<PmsSkuInfo> getInfo(@PathVariable("skuId") Long skuId){
        return Result.success(pmsSkuInfoService.getInfo(skuId));
    }

    /**
     * 根据商户Id查看低库存列表
     * @param shopId
     * @return
     */
    @GetMapping("/findLowInventoryNumSkuList/{shopId}")
    public Result<List<PmsSkuInfo>> findLowInventoryNumSkuList(@PathVariable("shopId") Long shopId){
        List<PmsSkuInfo> list = pmsSkuInfoService.findLowInventoryNumSkuList(shopId);
        return Result.success(list);
    }



    /**
     * 根据shopId获取shop对象
     * @param shopId
     * @return
     */
    @GetMapping("/findShopByShopId/{shopId}")
    public Result<PmsShop> findShopByShopId(@PathVariable("shopId") Long shopId){
        return pmsSkuInfoService.findShopByShopId(shopId);
    }
}
